package top.kaoshanji.p2ch10a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p2ch10a-315页a：运行finalize方法的示例
 * author kaoshanji
 * ^_^
 * create time 2025/2/2 17:42
 */
public class RunFinalize {

    private static final Logger logger = LogManager.getLogger(RunFinalize.class);

    @Override
    protected void finalize() throws Throwable {
        System.out.println("运行finalize方法。");
        super.finalize();
    }

    public static void main(String[] args) throws InterruptedException {
        logger.info("...代码清单-p2ch10a-315页a：运行finalize方法的示例...");

        RunFinalize runFinalize = new RunFinalize();
        runFinalize = null;

        for (int i = 0; i < 10; i++) {
            System.gc();
            Thread.sleep(100);
        }

    }

}
